package com.pap.rocketmq.service.impl;

import com.alibaba.fastjson.JSON;
import com.pap.rocketmq.entity.Mq;
import com.pap.rocketmq.entity.MqCount;
import com.pap.rocketmq.repository.MqCountRepository;
import com.pap.rocketmq.repository.MqRepository;
import com.pap.rocketmq.service.IMqCountService;
import com.pap.rocketmq.service.IMqService;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.TransactionMQProducer;
import org.apache.rocketmq.client.producer.TransactionSendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.swing.text.html.Option;
import java.util.Optional;
import java.util.concurrent.*;

@Transactional
@Service("mqCountService")
public class MqCountServiceImpl implements IMqCountService {

    private static Logger logger = LoggerFactory.getLogger(MqCountServiceImpl.class);


    @Autowired
    MqCountRepository mqCountRepository;

    @Override
    public boolean updateCount() {
        mqCountRepository.updateCount();
        return true;
    }

    @Override
    public int save(String id, String name, String msgId) {
        MqCount mqCount = new MqCount();
        mqCount.setId(msgId);
        mqCount.setMsgId(name);
        mqCount.setCount(id);
        mqCountRepository.save(mqCount);
        return 1;
    }

    @Override
    public MqCount selectById(String id) {
        Optional<MqCount> mqOption = mqCountRepository.findById(id);
        if(mqOption.isPresent()) {
            return mqOption.get();
        }
        return null;
    }
}